package dao;

import entity.Post;
import org.nutz.dao.Cnd;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import util.core.DataAccess;

import java.util.Date;
import java.util.List;

/**
 * Created by WhiteBlue on 15/6/17.
 */
public class PostDao extends DataAccess {

    public QueryResult listByPage(int pageNumber) {
        Pager pager = getDao().createPager(pageNumber, 2);
        List<Post> list = getDao().query(Post.class, Cnd.orderBy().desc("time"), pager);
        return new QueryResult(list, pager);
    }

    public void addPost(String name, String content) {
        Post post = new Post();
        post.setName(name);
        post.setContent(content);
        post.setTime(new Date());
        getDao().insert(post);
    }

}
